<template>
    <div class="juan">
        <el-dialog  :title="title" :visible.sync="open" width="65%" append-to-body :before-close="closeDelDialog" >
            <el-tabs v-model="activeName" @tab-click="handleClick">
                <el-tab-pane label="卷层" name="0" style="height: 300px;" :disabled='isAdd'>
                    <div style=" height: 700px;overflow-y: auto;width:80%;margin: auto;">
                        <addField v-if="infoList.length > 0" :infoList="infoList" :inputParams="inputParams"
                            @onChangeTap="onChangeTap"  :leftjianjuanMain="'leftMain'"></addField>
                        <el-empty v-else description="暂无著录数据" class="leftMain"></el-empty>
                    </div>
                </el-tab-pane>
                <el-tab-pane label="卷内件层" name="1" :disabled='disabled'>
                    <queryCriteriaList v-if="listFrom.length > 0" :showSearch="showSearch" :listFrom="listFrom"
                        @resetQuery="resetQuery" @handleQuery="handleQuery" ref="queryForm"></queryCriteriaList>
                    <el-row :gutter="10" class="mb8" ref="refbut">
                        <!-- <el-col :span="1.5">
                            <el-button type="primary" plain icon="el-icon-takeaway-box" >接收</el-button>
                        </el-col> -->
                        <el-col :span="1.5">
                            <el-button type="primary" plain icon="el-icon-plus"
                                @click="handledeitTap(0)" v-hasPermi="['archive:lxjs:addYqdaDgd']">著录</el-button>
                        </el-col>
                        <el-col :span="1.5">
                            <el-button type="success" plain icon="el-icon-edit"
                                @click="handledeitTap(1)" v-hasPermi="['archive:lxjs:updateYqdaDgd']">修改</el-button>
                        </el-col>
                        <el-col :span="1.5">
                            <el-button type="danger" plain icon="el-icon-delete" @click="handleDeleteTap"
                                >删除</el-button>
                        </el-col>
                        <el-col :span="1.5">
                            <el-button type="info" plain icon="el-icon-upload2"
                                @click="handleImport">导入</el-button>
                        </el-col>
                        <el-col :span="1.5">
                            <el-button type="warning" plain icon="el-icon-printer" v-hasPermi="['archive:dgd:JnjMldy']" @click="print1Tap">目录打印</el-button>
                        </el-col>
                        <!--
                            1.isShow==true,  是离线接收状态下
                            2.subStr==X,   是项目层的情况下
                           3.subStr==V   是修改项目层的卷情况下
                         -->
                        <!-- {{isShow}}{{openInfo.subStr}} {{ openInfo }}======================= -->
                        <el-col :span="1.5" v-if="(isShow && openInfo.subStr == 'X')">
                            <el-button type="success" icon="el-icon-plus" @click="projectJianClick()">著录项目内件</el-button>
                        </el-col>
                        <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar> -->
                    </el-row>
                    <el-row :style="'height:' + tableHeight + 'px'">
                        <el-col :span="24">

                            <tableList v-if="tableHeight > 0" :tableHeaderList="tableHeaderList"
                                @handleSelectionChange="handleSelectionChange" :tableData="tableData" :loading="loading"
                                @celldblclick="celldblclick" :tableHeight="tableHeight"></tableList>
                            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                                :limit.sync="queryParams.pageSize" @pagination="getlistPost" />
                        </el-col>
                    </el-row>


                </el-tab-pane>

            </el-tabs>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="closeDelDialog">取消</el-button>
                <el-button type="primary" @click="submitDetail(1)"
                    v-if="activeName == 0 && openInfo.ids == undefined">继承追加</el-button>
                <el-button type="primary" @click="submitDetail()" v-if="activeName == 0">确定</el-button>
                <el-button type="primary" @click="submitDetail1" v-if="activeName == 1">确定</el-button>
            </div>

        </el-dialog>
        <!-- start 组件著录、修改 -->
        <jiandeit v-if="jianOpen" :open="jianOpen" :openInfo="openInfo" @closeDelDialog="closeDelDialogJian"
            @submitDetail="submitDetailJian" :isParams="isParams" ref="refDeit" >
        </jiandeit>
        <!-- end  组件著录、修改-->
        <!--start  组件详情 -->
        <jianDetailsOpen v-if="jianDetailsOpen" :open="jianDetailsOpen" :celldbData="celldbData"
            @detailsHandleClose="detailsHandleClose">
        </jianDetailsOpen>
        <!--end 组件详情 -->

        <!-- start 项目下面的件列表 -->
        <projectJianList v-if="projectJianListOpen" :open="projectJianListOpen" @detailsHandleClose="detailsHandleClose"
            :openInfo="openInfo" :parentId="parentId" @handleAddTap="handleAddTap"></projectJianList>
        <!-- end  项目下面的件列表 -->

        <!-- 用户导入对话框 -->
        <dataImport :upload="upload" @uploadCancel="uploadCancelTap" @importTemplate="importTemplateTap"
            @uploadFile="uploadFile" @submitFileForm="submit"></dataImport>

        <!-- 导入匹配页 -->
        <importMatch :match="match" ref="matchRef" @matchCancel="matchCancelTap" @submitMatch="submitMatch"></importMatch>
    </div>
</template>
<script>
import {
  getrelevanceforadd,
  mergeYqda,
  assemblyFolder,
  getaddfield,
  getupdatefield,
  addFolder,
  getFolderById,
  updateFolder,
  getqueryfieldList,
  getshowfield,
  getlistbyparentId,
  deleteData,
  getjianlistbyjianids,
  getjianlistbyitemId,
  getTitle,
  uploadList,
  geturl, deleteData7, addFolder1, getDataInfo, updateFolderDgd, addFolderDgd
} from "@/api/archive/fileCollection/offlinReception.js";
import addField from "@/views/archive/fileCollection/offlinReception/addField.vue"  //著录字段列表
import { getGroupTree } from "@/api/archive/archivesCategory.js"
import queryCriteriaList from "@/components/queryCriteriaList/index.vue"  //查询列表
import tableList from "@/components/tableList/index.vue" //table
// import jiandeit from "@/views/archive/fileCollection/fileOrganization/fileQrganizationTobeArchived/jiandeit.vue" //件添加修改弹窗
import jiandeit from "@/views/archive/fileCollection/offlinReception/jiandeit.vue" //件添加修改弹窗
import {
    addDaFolder,
    addDaFolder1,
    updateDaFolder,
    updateDaFolder1
} from "@/api/archive/digitalizeReceive/archiveReception";  // 数字化成果接收--档案接收
import jianDetailsOpen from '@/components/componentsJianDetails/index.vue' //件详情
import projectJianList from "@/views/archive/fileCollection/offlinReception/projectJianList.vue" //项目下的件列表弹窗
import dataImport from "@/components/dataImportComponent/dataImport.vue";
import importMatch from "@/components/dataImportComponent/importMatch.vue";
import { getLastIndexOf } from "@/utils/index.js"
import { assemblyFolderygd } from "@/api/archive/fileCollection/fileOrganization.js"
import {zxjsMergeYqda} from "@/api/archive/fileCollection/onlineReception";
export default {
    //isZUXIU 判断项目下的案卷著录  还是案卷修改  1:著录  2修改
    //isShow  著录项目内件是否显示   只有离线接收显示
    //isType 在线收集的组卷按钮
    archive_Dicts: ['MJ', 'BGQX', 'IS_OPENS', 'CSLY', 'JS_TYPE'],
    props: ["open", "openInfo", "isParams", 'isZUXIU', "isShow", 'isType'],
    components: {
        addField,
        queryCriteriaList,
        tableList,
        jiandeit,
        jianDetailsOpen,
        projectJianList,
        dataImport,
        importMatch
    },
    data() {
        return {

            loading: true,
            parentId: undefined,
            jianOpen: false,
            tableHeight: "",
            activeName: "0",
            inputParams: "", //点击修改时获取的查询框的数据
            lists: [],
            inputList: [],
            infoList: [],
            disabled: true, //判断著录卷之后才可以著录卷内件
            isAdd: false,//著录的时候调用了添加接口 卷切换禁用
            listFrom: [], //查询框列表
            // 显示搜索条件
            showSearch: true,
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                subTableName: undefined
            },
            tableHeaderList: [], //table表头数据

            tableData: [],//table列表数据
            total: 0,
            ids: undefined,
            single: true,
            multiple: true,
            text: "操作成功",
            // 标题
            title: '',
            jianDetailsOpen: false,
            jianids: undefined,
            projectJianListOpen: false, //项目下面的件列表弹窗
            daIdsArr: [],
            // 用户导入参数
            upload: {
                // 是否显示弹出层（用户导入）
                open: false,
                // 弹出层标题（用户导入）
                title: "",
            },
            // 导入文件类型  件、卷、项目
            uploadType: null,
            // 表格表头
            xlsTitle: [],
            // 可导入项
            sysTitle: [],
            // 匹配参数
            match: {
                // 是否显示弹出层
                open: false,
                // 弹出层标题
                title: "",
            },
            BGQXList: [],//保管期限
            gxgxList: [],//关联关系列表
        }
    },
    watch: {
        openInfo: {
            handler(valNew) {
        //        console.log(valNew)
                //如果valNew.itemId！=undefined,那么disabled:false, 不需要著录件之后才可以点击著录卷内件，都可以进行点击切换
                if (valNew.itemId != undefined && this.isShow) {
                    this.disabled = false
                }

                if (valNew.isDisabled == 1 || valNew.isDisabled == 2) { //判断如果从组卷按钮和合并卷按钮进去带参isDisabled，只可以将件组成卷或者将多个卷里面的件合并，不可以在里面添加件
                    if (valNew.isDisabled == 1) {
                        this.title = '组卷'
                    } else {
                        this.title = '合并卷'
                    }
                    this.disabled = true;
                    this.getaddfieldPost({
                        categoryId: valNew.categoryId,
                        menuId: valNew.menuId,
                        type: valNew.type
                    })
                } else { //著录卷按钮点击的时候才可以著录卷的同时著录件
                    if (valNew.ids == undefined) { //添加
                        if (valNew.label == undefined) {
                            this.title = '组卷著录'
                        } else {
                            this.title = valNew.label
                        }

                        this.getaddfieldPost({
                            categoryId: valNew.categoryId,
                            menuId: valNew.menuId,
                            type: valNew.type
                        })
                        this.parentId = undefined
                    } else {
                        if (valNew.label == undefined) {
                            this.title = '组卷修改'
                        } else {
                            this.title = valNew.label
                        }
                        //修改
                        this.getUpdatefieldPost(valNew);
                        this.disabled = false;
                        this.parentId = valNew.ids;
                        this.isState = valNew.ids;
                    }

                    //

                }
            },
            immediate: true
        },
    },
    created() {
        this.getDicts_archive('GXGX').then(response => {
            this.gxgx = response.data
        })

        this.getDicts_archive('BGQX').then(response => {
            this.BGQXList = response.data
        })

    },
    // props: ["openInfo", "open"],
    methods: {
        //动态设置table的高度
        tableHeightData() {
            this.$nextTick(
                () => {
                    let h = 650;

                    //  h = h + 100
                    if (this.$refs.queryForm) { // 页面上如果有面包屑区域徐减去它的高度
                        h = h - this.$refs.queryForm.$el.offsetHeight
                    }

                    if (this.$refs.refbut) { // 页面上如果有分页区域徐减去它的高度
                        h = h - this.$refs.refbut.$el.offsetHeight
                    }
                    this.tableHeight = h > 310 ? h : 310 // 根据自己项目定高度
                    return h
                }
            )
        },
        //获取著录字段
        getaddfieldPost(data) {


            var that = this;
            this.$modal.loading("加载中...")
            getaddfield(data).then(response => {
                this.lists = response.data.addColumn;
                var listData = response.data.addColumn;
                let dataInfo = {};
                let arr = {}; //设置默认值
                let gxgxShowType={};
                // console.log(this.openInfo, "*******************")
                //设置关联关系
                if (this.openInfo.folderId != undefined || this.openInfo.itemId != undefined) {
                    getrelevanceforadd({
                        categoryId: data.categoryId,
                        level: data.type,
                        itemId: this.openInfo.itemId,
                        folderId: this.openInfo.folderId
                    }).then(res => {
                        if (res.code == "200") {
                            this.gxgxList = res.data;
                            res.data.forEach((item, index) => {
                                listData.forEach((itemx, idx) => {
                                    if (itemx.SHOWTYPE == 7 || itemx.SHOWTYPE == 8 || itemx.SHOWTYPE == 10) {
                                        if (item.FIELDNAME == itemx.FIELD_NAME + "_ID") {
                                            gxgxShowType[item.FIELDNAME]=item.VALUE
                                        }

                                    }
                                    if (item.FIELDNAME == itemx.FIELD_NAME) {
                                        itemx.DEFAULT_VALUE = item.VALUE
                                    }
                                })
                            })

                            listData.forEach((item, index) => {
                                arr[item.FIELD_NAME] = item.DEFAULT_VALUE // 根据自己需求可以拼接
                                let { ZSFL } = item;
                                if (!dataInfo[ZSFL]) {
                                    dataInfo[ZSFL] = {
                                        ZSFL,
                                        child: []
                                    }
                                }
                                dataInfo[ZSFL].child.push(item);
                            });
                    //        console.log(dataInfo, "劉海榮")
                          let merged = {...arr, ...gxgxShowType};
                            this.setSessionStorage(this.lists);
                            this.infoList = Object.values(dataInfo); // list 转换成功的数据
                            this.inputParams = {};  //添加时传{}
                            this.getRQ(merged.RQ)
                            this.inputParams = merged;  //修改获取的输入框参数

                            this.inputList = merged; //修改时用来判断提示窗是否有值

                            this.$modal.closeLoading()
                        }

                    })
                } else {
                    that.$nextTick(function (res) {
                        listData.forEach((item, index) => {
                            arr[item.FIELD_NAME] = item.DEFAULT_VALUE // 根据自己需求可以拼接
                            let { ZSFL } = item;
                            if (!dataInfo[ZSFL]) {
                                dataInfo[ZSFL] = {
                                    ZSFL,
                                    child: []
                                }
                            }
                            dataInfo[ZSFL].child.push(item);
                        });
                      //  console.log(arr, "+++")
                        this.setSessionStorage(this.lists);
                        this.infoList = Object.values(dataInfo); // list 转换成功的数据
                        this.inputParams = {};  //添加时传{}
                        this.getRQ(arr.RQ)
                        this.inputParams = arr;  //修改获取的输入框参数

                        this.inputList = arr; //修改时用来判断提示窗是否有值

                        this.$modal.closeLoading()
                    })
                }


            });
        },
        //获取修改字段
        getUpdatefieldPost(data) {
            this.$modal.loading("加载中...")
            getupdatefield({
                categoryId: data.categoryId,
                menuId: data.menuId,
                type: data.type
            }).then(response => {
                if (response.data.updateColumn.length > 0) {
                    this.lists = response.data.updateColumn;
                    var listData = response.data.updateColumn;
                    let dataInfo = {};
                    listData.forEach((item, index) => {
                        let { ZSFL } = item;
                        if (!dataInfo[ZSFL]) {
                            dataInfo[ZSFL] = {
                                ZSFL,
                                child: []
                            }
                        }
                        dataInfo[ZSFL].child.push(item);
                    });

                    this.setSessionStorage(this.lists);
                    this.infoList = Object.values(dataInfo); // list 转换成功的数据
                    this.getYqdaByIdPost(data, this.lists);
                    this.$modal.closeLoading()
                }
            });

        },

        // //获取的查询添加list  改成["MJ","BGQX"] 用于动态显示下拉用方法
        setSessionStorage(valNew) {
            var data = [];
            for (var i in valNew) {
                if (valNew[i].SHOWTYPE == 5) {
                    data.push(valNew[i].FIELD_NAME)
                }
            }
            sessionStorage.setItem("data", JSON.stringify(data))
        },

        /**
         * 修改字段
         * 获取组卷详情**/
        getYqdaByIdPost(data, lists) {
            var column = [];
            for (var i in lists) {
                if (lists[i].SHOWTYPE == 7 || lists[i].SHOWTYPE == 8 || lists[i].SHOWTYPE == 10) {
                    column.push(lists[i].FIELD_NAME + '_ID')
                }
                column.push(lists[i].FIELD_NAME)
            }
            getFolderById({
                categoryId: data.categoryId,
                id: data.ids,
                column: column.toString()
            }
            ).then(res => {
                // if (res.data.RQ != null) {
                //     if (typeof (res.data.RQ) == "number") {
                //         res.data.RQ = res.data.RQ.toString();
                //     }
                //     if (res.data.RQ.toString().indexOf('/') != -1) {
                //         res.data.RQ = this.parseTime(res.data.RQ, '{y}{m}{d}');
                //     }

                //     var regDate = /(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})(((0[13578]|1[02])(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)(0[1-9]|[12][0-9]|30))|(02(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))0229)/;
                //     var isDate = regDate.test(res.data.RQ);
                //     if (!isDate) {
                //         // console.log("日期格式有误。请按示例格式填写");
                //         const date = new Date()
                //         const year = date.getFullYear()
                //         const month = ('0' + (date.getMonth() + 1)).slice(-2)
                //         const day = ('0' + date.getDate()).slice(-2)
                //         res.data.RQ = year + "" + month + "" + day;
                //         // return;
                //     }

                // }

                this.getRQ(res.data.RQ)
                this.inputParams = res.data;  //修改获取的输入框参数
                this.inputList = res.data; //修改时用来判断提示窗是否有值
            })
        },


        getRQ(RQ) {
       //     console.log(RQ, "888888888888888888888")
            if (RQ != null) {
                if (typeof (RQ) == "number") {
                    RQ = RQ.toString();
                }
                if (RQ.toString().indexOf('/') != -1) {
                    RQ = this.parseTime(RQ, '{y}{m}{d}');
                }

                var regDate = /(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})(((0[13578]|1[02])(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)(0[1-9]|[12][0-9]|30))|(02(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))0229)/;
                var isDate = regDate.test(RQ);
                if (!isDate) {
           //         console.log("日期格式有误。请按示例格式填写");
                    const date = new Date()
                    const year = date.getFullYear()
                    const month = ('0' + (date.getMonth() + 1)).slice(-2)
                    const day = ('0' + date.getDate()).slice(-2)
                    RQ = year + "" + month + "" + day;
                    // return;
                }

            }
        },

        //获取input 输入框字段
        onChangeTap(data) {
            this.inputList = data;
            for (var i in this.infoList) {
                for (var j in this.infoList[i].child) {
                    this.infoList[i].child[j].DEFAULT_VALUE = null;

                }
            }


        },
        //关闭
        closeDelDialog() {
            this.infoList = [];
            this.$modal.closeLoading()
            this.$emit("closeDelDialog")
        },
        //切换
        handleClick() {
            this.tableHeightData();
            this.getGroupTreePost(this.openInfo)
        },

        //确定
        submitDetail(val) {
            var that = this;
            //将数据从新排序为了弹窗提示做准备
            var arr = [];
            var arrList = [];
            for (var i in this.infoList) {
                for (var j in this.infoList[i].child) {

                    arrList.push(this.infoList[i].child[j]);
                    if (this.infoList[i].child[j].IS_NO_EMPTY != 0) {
                        arr.push(this.infoList[i].child[j])
                    }
                }
            }

            var column = [];

            for (var n in arr) {
                for (var k in this.inputList) {
                    if (arr[n].FIELD_NAME == k) {
                        arr[n].DEFAULT_VALUE = this.inputList[k]
                    }
                }

                if (arr[n].DEFAULT_VALUE == undefined || arr[n].DEFAULT_VALUE == null) {
                    this.$message({ message: '请输入' + arr[n].FIELD_CAPTION + '!', type: 'warning' })
                    return
                }
            }

            for (var t in arrList) {
                for (var v in this.inputList) {
                    if (arrList[t].FIELD_NAME == v) {
                        arrList[t].DEFAULT_VALUE = this.inputList[v]
                    }
                }


            }

            var text = ""
            for (var y in arrList) {
                // console.log(arrList[y],"____")
                for (var m in this.gxgxList) {
                    //   console.log(this.gxgxList[m].FIELDNAME ,arrList[y].FIELD_NAME,"fjkdlsjf")
                    if (this.gxgxList[m].FIELDNAME == arrList[y].FIELD_NAME) {
                        if (this.gxgxList[m].FROMLEVEL == 0) {
                            text = "件层"
                        } else if (this.gxgxList[m].FROMLEVEL == 1) {
                            text = "卷层"
                        } else {
                            text = "项目层"
                        }
                        // console.log(this.gxgxList[m] ,"liuhaiorng")
                        //相等关系 RELATION=0
                        if (this.gxgxList[m].RELATION == 0) {
                            if (this.gxgxList[m].VALUE != arrList[y].DEFAULT_VALUE) {
                                this.$message({ message: arrList[y].FIELD_CAPTION + '关联关系必须是和' + text + '的' + arrList[y].FIELD_CAPTION + '相等关系哦', type: 'warning' })
                                return
                            }
                        }

                        //大于等于 RELATION=4
                        if (this.gxgxList[m].RELATION == 4) {
                            var VALUE = this.gxgxList[m].VALUE;
                            var DEFAULT_VALUE = arrList[y].DEFAULT_VALUE;
                            if (this.gxgxList[m].FIELDNAME == "BGQX") {
                                VALUE = VALUE.substring(1);
                                DEFAULT_VALUE = DEFAULT_VALUE.substring(1);
                                var dictValue = this.BGQXList.filter((item) => { return item.dictValue == this.gxgxList[m].VALUE })
                                var NAME = dictValue[0].dictLabel;
                                var DEFAULT_dictValue = this.BGQXList.filter((item) => { return item.dictValue == arrList[y].DEFAULT_VALUE })
                                var DEFAULT_MAME = DEFAULT_dictValue[0].dictLabel;
                                if (NAME == "永久") {
                                    if (NAME != DEFAULT_MAME) {
                                        this.$message({ message: arrList[y].FIELD_CAPTION + '关联关系必须是大于等于' + text + '的' + arrList[y].FIELD_CAPTION + '哦', type: 'warning' })
                                        return
                                    }

                                } else {
                                    if (DEFAULT_MAME != "永久") {
                                        if (!(parseInt(VALUE) <= parseInt(DEFAULT_VALUE))) {
                                            this.$message({ message: arrList[y].FIELD_CAPTION + '关联关系必须是大于等于' + text + '的' + arrList[y].FIELD_CAPTION + '哦', type: 'warning' })
                                            return
                                        }

                                    }
                                }

                            } else {

                                if (!(parseInt(VALUE) <= parseInt(DEFAULT_VALUE))) {
                                    this.$message({ message: arrList[y].FIELD_CAPTION + '关联关系必须是大于等于' + text + '的' + arrList[y].FIELD_CAPTION + '哦', type: 'warning' })
                                    return
                                }
                            }

                       //     console.log(parseInt(VALUE) <= parseInt(DEFAULT_VALUE), parseInt(VALUE), NAME, parseInt(DEFAULT_VALUE), DEFAULT_MAME, this.gxgxList[m].VALUE, arrList[y].DEFAULT_VALUE)
                        }

                        //大于  RELATION=1
                        if (this.gxgxList[m].RELATION == 1) {
                            var VALUE = this.gxgxList[m].VALUE;
                            var DEFAULT_VALUE = arrList[y].DEFAULT_VALUE;
                            if (this.gxgxList[m].FIELDNAME == "BGQX") {
                                VALUE = VALUE.substring(1);
                                DEFAULT_VALUE = DEFAULT_VALUE.substring(1);
                                var dictValue = this.BGQXList.filter((item) => { return item.dictValue == this.gxgxList[m].VALUE })
                                var NAME = dictValue[0].dictLabel;
                                var DEFAULT_dictValue = this.BGQXList.filter((item) => { return item.dictValue == arrList[y].DEFAULT_VALUE })
                                var DEFAULT_MAME = DEFAULT_dictValue[0].dictLabel;

                                if (NAME == "永久") {
                                    this.$message({ message: arrList[y].FIELD_CAPTION + '关联关系必须是大于' + text + '的' + arrList[y].FIELD_CAPTION + '哦', type: 'warning' })
                                    return

                                } else {
                                    if (DEFAULT_MAME != "永久") {
                                        if (!(parseInt(VALUE) < parseInt(DEFAULT_VALUE))) {
                                            this.$message({ message: arrList[y].FIELD_CAPTION + '关联关系必须是大于' + text + '的' + arrList[y].FIELD_CAPTION + '哦', type: 'warning' })
                                            return
                                        }
                                    }

                                }

                            } else {
                           //     console.log(parseInt(VALUE) < parseInt(DEFAULT_VALUE), parseInt(VALUE), parseInt(DEFAULT_VALUE), this.gxgxList[m].VALUE, arrList[y].DEFAULT_VALUE)
                                if (!(parseInt(VALUE) < parseInt(DEFAULT_VALUE))) {
                                    this.$message({ message: arrList[y].FIELD_CAPTION + '关联关系必须是大于' + text + '的' + arrList[y].FIELD_CAPTION + '哦', type: 'warning' })
                                    return
                                }
                            }
                        }

                        //小于等于  RELATION=3
                        if (this.gxgxList[m].RELATION == 3) {
                            var VALUE = this.gxgxList[m].VALUE;
                            var DEFAULT_VALUE = arrList[y].DEFAULT_VALUE;

                            if (this.gxgxList[m].FIELDNAME == "BGQX") {
                                VALUE = VALUE.substring(1);
                                DEFAULT_VALUE = DEFAULT_VALUE.substring(1);
                                var dictValue = this.BGQXList.filter((item) => { return item.dictValue == this.gxgxList[m].VALUE })
                                var NAME = dictValue[0].dictLabel;
                                var DEFAULT_dictValue = this.BGQXList.filter((item) => { return item.dictValue == arrList[y].DEFAULT_VALUE })
                                var DEFAULT_MAME = DEFAULT_dictValue[0].dictLabel;
                                if (NAME == "永久") {
                                } else {
                                    if (DEFAULT_MAME != "永久") {
                                        if (!(parseInt(VALUE) >= parseInt(DEFAULT_VALUE))) {
                                            this.$message({ message: arrList[y].FIELD_CAPTION + '关联关系必须是小于等于' + text + '的' + arrList[y].FIELD_CAPTION + '哦', type: 'warning' })
                                            return
                                        }
                                    } else {
                                        this.$message({ message: arrList[y].FIELD_CAPTION + '关联关系必须是小于等于' + text + '的' + arrList[y].FIELD_CAPTION + '哦', type: 'warning' })
                                        return
                                    }
                                }

                            } else {

                                if (!(parseInt(VALUE) >= parseInt(DEFAULT_VALUE))) {
                                    this.$message({ message: arrList[y].FIELD_CAPTION + '关联关系必须是小于等于' + text + '的' + arrList[y].FIELD_CAPTION + '哦', type: 'warning' })
                                    return
                                }
                            }

                    //        console.log(parseInt(VALUE) >= parseInt(DEFAULT_VALUE), parseInt(VALUE), NAME, parseInt(DEFAULT_VALUE), DEFAULT_MAME, this.gxgxList[m], arrList[y])

                        }


                        //小于  RELATION=2
                        if (this.gxgxList[m].RELATION == 2) {
                            var VALUE = this.gxgxList[m].VALUE;
                            var DEFAULT_VALUE = arrList[y].DEFAULT_VALUE;
                            if (this.gxgxList[m].FIELDNAME == "BGQX") {
                                VALUE = VALUE.substring(1);
                                DEFAULT_VALUE = DEFAULT_VALUE.substring(1);
                                var dictValue = this.BGQXList.filter((item) => { return item.dictValue == this.gxgxList[m].VALUE })
                                var NAME = dictValue[0].dictLabel;
                                var DEFAULT_dictValue = this.BGQXList.filter((item) => { return item.dictValue == arrList[y].DEFAULT_VALUE })
                                var DEFAULT_MAME = DEFAULT_dictValue[0].dictLabel;
                                console.log(NAME, DEFAULT_MAME)
                                if (NAME == "永久") {
                                    if (DEFAULT_MAME == "永久") {
                                        this.$message({ message: arrList[y].FIELD_CAPTION + '关联关系必须是小于' + text + '的' + arrList[y].FIELD_CAPTION + '哦', type: 'warning' })
                                        return
                                    }
                                } else {
                                    if (DEFAULT_MAME == "永久") {
                                        this.$message({ message: arrList[y].FIELD_CAPTION + '关联关系必须是小于' + text + '的' + arrList[y].FIELD_CAPTION + '哦', type: 'warning' })
                                        return
                                    } else {
                                        if (!(parseInt(VALUE) > parseInt(DEFAULT_VALUE))) {
                                            this.$message({ message: arrList[y].FIELD_CAPTION + '关联关系必须是小于' + text + '的' + arrList[y].FIELD_CAPTION + '哦', type: 'warning' })
                                            return
                                        }
                                    }

                                }
                            } else {

                                if (!(parseInt(VALUE) > parseInt(DEFAULT_VALUE))) {
                                    this.$message({ message: arrList[y].FIELD_CAPTION + '关联关系必须是小于' + text + '的' + arrList[y].FIELD_CAPTION + '哦', type: 'warning' })
                                    return
                                }
                            }

                    //        console.log(parseInt(VALUE) > parseInt(DEFAULT_VALUE), parseInt(VALUE), parseInt(DEFAULT_VALUE), this.gxgxList[m].VALUE, arrList[y].DEFAULT_VALUE)
                        }

                    }
                }
            }
            for (var i in this.inputList) {
                column.push({
                    name: i,
                    value: this.inputList[i],
                })
            }



            if (this.openInfo.isDisabled == 1) { //组卷
                // 在线收集
                if (this.isType == 'online') {
                  this.disabled = true //组卷的时候不能显示卷内件层列表
                  zxjsMergeYqda({
                    categoryId: this.openInfo.categoryId,
                    column: column,
                    daIds: this.openInfo.ids
                  }).then(res => {
                    if (res.code == "200") {
                      this.$modal.msgSuccess("组卷成功");
                      this.$emit("submitDetail")
                    }
                  }).catch(res => {
                    this.$emit("submitDetail")
                  })
                } else{ // 离线收集
                  this.disabled = true //组卷的时候不能显示卷内件层列表
                  mergeYqda({
                    categoryId: this.openInfo.categoryId,
                    column: column,
                    daIds: this.openInfo.ids
                  }).then(res => {
                    if (res.code == "200") {
                      this.$modal.msgSuccess("组卷成功");
                      this.$emit("submitDetail")
                    }
                  }).catch(res => {
                    this.$emit("submitDetail")
                  })
                }
            } else if (this.openInfo.isDisabled == 2) { //合并卷
                if (this.openInfo.source == 'ygd') { // 预归档的合并卷
                    this.disabled = true //合并卷的时候不能显示卷内件层列表
                    assemblyFolderygd({
                        categoryId: this.openInfo.categoryId,
                        column: column,
                        folderIds: this.openInfo.ids
                    }).then(res => {
                        if (res.code == "200") {
                            this.$modal.msgSuccess("合并卷成功");
                            this.$emit("submitDetail")
                        }
                    }).catch(res => {
                      this.$emit("submitDetail")
                    })
                } else {
                    this.disabled = true //合并卷的时候不能显示卷内件层列表
                    assemblyFolder({
                        categoryId: this.openInfo.categoryId,
                        column: column,
                        folderIds: this.openInfo.ids
                    }).then(res => {
                        if (res.code == "200") {
                            this.$modal.msgSuccess("合并卷成功");
                            this.$emit("submitDetail")
                        }
                    }).catch(res => {
                      this.$emit("submitDetail")
                    })
                }
            } else {
                console.log(this.openInfo)
              this.$modal.loading("加载中...")
              if (this.isState != undefined) {
                var daIds = ''
                if (this.jianids == undefined || this.jianids == '-1') {
                  daIds = undefined;
                } else {
                  daIds = this.queryParams.jianids
                }
                // 项目层案卷修改
                updateFolderDgd(
                  {
                    categoryId: this.openInfo.categoryId,
                    id: this.openInfo.ids,
                    column: column,
                    daIds: daIds
                  }
                ).then(res => {
                  this.activeName = "1" //校验通过设置
                  that.text = "修改成功";
                  that.$modal.msgSuccess("修改成功");
                  // this.infoList = []
                  that.$modal.closeLoading()
                  that.tableHeightData(); //获取table表格高度
                  // this.getlistHeaderPost(this.openInfo);
                  this.getGroupTreePost(this.openInfo)

                }).catch(res => {
                  this.$modal.closeLoading()
                })
              } else {
                var daIds = ''
                if (this.jianids == undefined || this.jianids == '-1') {
                  daIds = undefined;
                } else {
                  daIds = this.queryParams.jianids
                }
                // 项目案卷著录
                addFolderDgd(
                  {
                    itemId: this.openInfo.itemId, //项目下著录组卷 需要这个项目的ID字段
                    categoryId: this.openInfo.categoryId,
                    column: column,
                    daIds: daIds,
                  }
                ).then(res => {
                  that.$modal.closeLoading()

                  if (val == 1) { //继承追加按钮
                    that.queryParams.parentId = res.msg;
                    that.parentId = res.msg; //添加完将返回的卷ID存起来，再次提交的时候调用修改接口
                    setTimeout(function () {
                      that.$modal.msgSuccess("著录成功");
                      that.text = "著录成功";
                    }, 1000)
                  } else {
                    that.activeName = "1" //校验通过设置
                    that.queryParams.parentId = res.msg;
                    that.parentId = res.msg; //添加完将返回的卷ID存起来，再次提交的时候调用修改接口
                    that.isState= res.msg; //判断添加还是修改
                    that.queryParams.isTitle= res.msg; //判断有没有卷ID  检测显示title用
                    that.tableHeightData(); //获取table表格高度
                    this.getGroupTreePost(this.openInfo)
                    that.infoList = []
                    that.disabled = false //判断著录卷之后才可以著录卷内件
                    that.isAdd = true
                    setTimeout(function () {
                      that.$modal.msgSuccess("著录成功");
                      that.text = "著录成功";
                    }, 1000)
                  }

                  console.log(this.openInfo,this.isState, that.queryParams,"___________________")
                }).catch(res => {
                  that.$modal.closeLoading()
                })
              }
            }

        },
        submitDetail1() {
            this.$modal.msgSuccess(this.text);
            this.$emit("submitDetail")
        },

        // id
        //档案门类树门类根据categoryID回显获取当前门类下面的的卷folderTableName
        getGroupTreePost(data) {
            getGroupTree(data.categoryId).then(response => {

                data.subTableName = response.data.fileTableName;  //件subTableName
                this.categoryinfo = response.data;
                // console.log(this.categoryinfo,"+++++++++++++++++++")
                this.getqueryfieldListPost(data);//点击树节点获取卷的查询字段
                this.getlistHeaderPost(data);/**点击树节点,获取卷table表头数据 */
            });
        },

        /** 获取查询字段 */
        getqueryfieldListPost(data) {

            // console.log(data,"+++++++++++++","获取查询字段")
            // if (getLastIndexOf(data.subTableName) == "F") {  //F 件
            //     level = 0
            // } else if (getLastIndexOf(this.queryParams.sub_table_name) == "V") { //卷
            //     level = 1
            // } else { //项目
            //     level = 3

            // }
            getqueryfieldList({
                categoryId: data.categoryId,
                menuId: data.menuId,
                subTableName: data.subTableName
            }).then(response => {
                this.listFrom = response.rows;
            });
        },

        /**获取table表头数据 */
        getlistHeaderPost(data) {
         //   console.log(data, "00000000000")
            getshowfield({
                categoryId: data.categoryId,
                menuId: data.menuId,
                level: "jian",
            }
            ).then(response => {
                this.tableHeaderList = response.data;
                var fields = []
                for (var i in response.data) {
                    fields.push(response.data[i].FIELD_NAME)
                }

                this.queryParams.fields = fields.toString()
                this.queryParams.menuId = data.menuId;
                this.queryParams.categoryId = data.categoryId
                if (data.ids != undefined) {
                    this.queryParams.parentId = data.ids;
                }

                this.queryParams.level = "1";
                this.getlistPost();

            });
        },

        /** 获取table数据*/
        getlistPost() {
            console.log(this.openInfo,this.parentId)
            //如果valNew.openInfo.itemId=undefined,意思是从案层 著录和件层 著录进入 调用getlistPost()列表, 否则是从项目层进入的案卷著录
            if (this.openInfo.itemId != undefined) {
                if (this.jianids == undefined) {
                    this.jianids = '-1';
                }
                this.queryParams.jianids = this.jianids
        //        console.log(this.queryParams.jianids, this.parentId, "1111111111111111111111")
                if (this.parentId != undefined) { //案卷是修改的时候进来显示的接口
                    getlistbyparentId(this.queryParams).then(response => {
                        this.tableData = response.rows;
                        this.total = response.total;
                        this.loading = false;

                    });
                } else { //案卷著录进来显示的接口
                    // 项目下的  案卷著录 获取的 table
                    getjianlistbyjianids(this.queryParams).then(response => {
                        this.tableData = response.rows;
                        this.total = response.total;
                        this.loading = false;
                    });


                }

            } else {
             //   console.log(this.queryParams, "++")
                //案卷著录   案件著录
                getlistbyparentId(this.queryParams).then(response => {
                    this.tableData = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            }



        },

        //是否选择数据
        handleSelectionChange(ids, single, multiple) {
            this.ids = ids.toString();
            this.single = single;
            this.multiple = multiple;
        },

        //删除
        handleDeleteTap() {
            if (this.ids != undefined && !this.multiple) {
                this.$modal.confirm('是否确认删除所选数据项？').then(function () {
                }).then(() => {
                    let subStr = getLastIndexOf(this.categoryinfo.fileTableName);
                    let type = "";
                    if (subStr == "F") {  //F 件
                        type = 0;
                    } else if (subStr == "V") { //卷
                        type = 1;
                    } else { //项目
                        type = 3;
                    }
                    deleteData7({
                        //nodeType: this.openInfo.nodeType,
                        type: type,
                        categoryId: this.openInfo.categoryId,
                        //sub_table_name: this.openInfo.sub_table_name,
                        //menuId: this.openInfo.menuId,
                        //parentNodeType: this.openInfo.parentNodeType,
                        //parentSubTableName: this.openInfo.parentSubTableName,
                        ids: this.ids
                    }).then(res => {
                        this.$modal.msgSuccess("删除成功");

                   //     console.log(this.ids, this.tableData, "______________________")
                        this.getlistPost();

                    })

                }).catch(() => { });
            } else {
                this.$message({ message: '请选择要删除的数据哦', type: 'warning' })
            }
        },
        //表单重置
        resetQuery() { },

        //点击搜索
        handleQuery(searchcolumn) {
            // console.log(searchcolumn)
            this.queryParams.searchcolumn = searchcolumn;
            this.getlistPost();
        },

        //卷内件层著录/修改弹窗
        handledeitTap(e) {
            if (e == 1) {  //修改
                if (this.ids == undefined) {
                    this.$message({ message: '请选择要修改的数据哦', type: 'warning' })
                    return false
                }
                if (this.single) {
                    this.$message({ message: '请选择一条要修改的数据哦', type: 'warning' })
                    return false
                }
                this.openInfo.ids = this.ids  //添加完将返回的卷ID存起来，再次提交的时候调用修改接口
                this.openInfo.button1 = 'jnjxg' //卷内件著录
            } else {
                //添加
                // console.log(this.parentId)
                // if(this.parentId!=undefined&&this.parentId!=null&&this.parentId!=''){
                //     this.openInfo.folderId=this.parentId
                // }

                this.openInfo.ids = undefined  //添加完将返回的卷ID存起来，再次提交的时候调用修改接口
                this.openInfo.button1 = 'jnjzl' //卷内件著录
            }

            this.jianOpen = true;
            this.openInfo.type = 0; //卷内件层传参type：0
            this.openInfo.folderId = this.parentId; //卷内件层传参
            this.openInfo.parentId=this.queryParams.parentId

        },

        //著录件层确定提交事件
        submitDetailJian() {
            this.jianOpen = false;
            this.isAdd=true; //著录完卷内件 禁用卷层
            this.openInfo.ids = this.queryParams.parentId;
            for(var i in this.$refs.refDeit.daIdsList ){
                this.daIdsArr.push(this.$refs.refDeit.daIdsList[i])
            }

            this.jianids = this.daIdsArr.toString();

            this.getlistPost();
        },
        //关闭卷内件层著录
        closeDelDialogJian() {
            this.jianOpen = false;

        },
        //双击列表进入详情页面
        celldblclick(row) {

            var level = "";
            this.celldbData = {
                id: row.ID,
                categoryId: this.openInfo.categoryId,
                menuId: this.queryParams.menuId,
                sub_table_name: this.categoryinfo.fileTableName,
                label: row.TITLE,
                level: 0,
                ifSub_table_name: this.categoryinfo.fileTableName,
                isDel: "0",  //判断是回收站数据还是接收收据 isDel:1  回收站    isDel:0 //离线接收、档案接收、在线接收
                tableHeaderList: this.tableHeaderList
            }
            this.jianDetailsOpen = true;


        },
        //关闭详情页面
        detailsHandleClose() {
            this.jianDetailsOpen = false;
            this.projectJianListOpen = false;
        },

        //打开项目下面的件列表弹窗事件
        projectJianClick() {
            this.projectJianListOpen = true
        },

        //项目内件添加事件
        handleAddTap(ids) {
            var idsList = ids.split(",")
            for (var i in idsList) {
                this.daIdsArr.push(idsList[i])
            }

            this.jianids = this.daIdsArr.toString();
            this.getlistPost();
            this.projectJianListOpen = false;
        },

        // 导入按钮  组件/项目
        handleImport() {
            // console.log("件导入")
            this.upload.title = "卷内件数据";
            this.upload.open = true;
            this.uploadType = 0

        },

        // 关闭导入  /件/卷/项目
        uploadCancelTap() {
            this.upload.open = false;
            this.getlistPost();
        },
        // 下载模板
        importTemplateTap() {
            this.form = {
                type: this.uploadType,
                categoryId: this.queryParams.categoryId
            }
            this.download('/archive/daImport/download?type=' + this.uploadType + "&categoryId=" + this.queryParams.categoryId, {
            }, `fileData_template_${new Date().getTime()}.xlsx`)
        },
        // 上传文件
        uploadFile(concent) {
            this.file = concent.file
            const formData = new FormData();
            formData.append("file", concent.file);
            formData.append("categoryId", this.queryParams.categoryId);
            formData.append("type", this.uploadType);
            getTitle(formData).then(response => {
                this.xlsTitle = response.data.xlsTitle.map(item => {
                    return {
                        xlsNum: item.num,
                        xlsName: item.name
                    }
                })
                this.sysTitle = response.data.sysTitle.map(item => {
                    return {
                        name: item.fieldName,
                        caption: item.fieldCaption,
                        showType: item.showType,
                        dataLength: item.dataLength,
                        isNoEmpty: item.isNoEmpty,
                        defaultValue: item.defaultValue,
                        checkChongfu: item.checkChongfu
                    }
                })
                this.$nextTick(() => {   //此函数执行时所有的DOM挂载和渲染都已完成
                    this.$refs.matchRef.init(this.xlsTitle, this.sysTitle);     //获取子组件中init方法并将父组件数据传递给子组件
                });
            })
        },

        // 点击确认
        submit() {
            // console.log("打开匹配页")
            this.upload.open = false
            this.match.open = true
            if (this.uploadType == 0) {
                this.match.title = "卷内件导入"
            } else if (this.uploadType == 1) {
                this.match.title = "案卷导入"
            } else {
                this.match.title = "项目导入"
            }
            // this.$nextTick(() => {   //此函数执行时所有的DOM挂载和渲染都已完成
            //     this.$refs.matchRef.init(this.xlsTitle, this.sysTitle);     //获取子组件中init方法并将父组件数据传递给子组件
            // });
        },
        submitMatch(matchedData) {
   //         console.log(this.queryParams, this.parentId, "++++")
            var state = undefined
            var jsType = undefined
            // 离线收集
            if (this.isParams == 1) {
                state = 1
                jsType = 0
            } else if (this.isParams == 2) { // 档案接收
                state = 3
                jsType = 2
            }
            this.form = {
                categoryId: this.queryParams.categoryId,
                state: state,
                jsType: jsType,
                colNames: matchedData,
                type: this.uploadType,
                itemId: this.openInfo.itemId,
                folderId: this.parentId
            }
            const formData = new FormData();
            formData.append("file", this.file);
            formData.append("dataStr", JSON.stringify(this.form));
            uploadList(formData).then(response => {
                this.$modal.msgSuccess(response.msg);
                // this.match.open = false;
                this.getlistPost()
            })
            this.match.open = false;
        },
        matchCancelTap() {
            this.match.open = false;
        },

        print1Tap() {
            var data = [];
            var datalist = ['data']
            this.printList = [];
            // console.log(this.categoryinfo,"+++++++++++++++++++++++")
            if (this.ids != undefined && !this.multiple) {
                var idsData = this.ids.split(",")
                for (var i in this.tableData) {
                    for (var j in idsData) {
                        if (this.tableData[i].ID == idsData[j]) {
                            this.printList.push(this.tableData[i])
                        }
                    }
                }
                data = [{ data: this.printList }];
                geturl({
                    categoryId: this.queryParams.categoryId,
                    menuId: this.queryParams.menuId,
                    type: getLastIndexOf(this.categoryinfo.fileTableName),
                    data: JSON.stringify(data),
                    datalist: JSON.stringify(datalist),
                }).then(res => {
                    if (res.data.result == "fail") {
                        this.$message({ message: res.data.msg, type: 'warning' })
                    } else {
                        window.open(res.data.url);
                    }


                })
            } else {
                this.$message({ message: '请选择要打印的数据哦', type: 'warning' })
            }
        },
    }
}
</script>
<style lang="scss" scoped>
::v-deep .el-dialog {
    margin: 20px auto 0 !important;
}

::v-deep .el-dialog__body {
    padding: 0 20px 10px !important;
}

::v-deep .el-tabs__content {
    overflow: visible;
}

.el-tabs {
    height: 770px;
}

::v-deep .leftMain {
    overflow: auto;
    height: 670px;
}
</style>
